export function formatDateTime(obj) {
  if (obj == null) {
    return null;
  }
  let date = new Date(obj);
  let y = 1900 + date.getYear();
  let m = "0" + (date.getMonth() + 1);
  let d = "0" + date.getDate();
  return y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length);
}

export function formatDateTimeYM(obj) {
  if (obj == null) {
    return null;
  }
  let date = new Date(obj);
  let y = 1900 + date.getYear();
  let m = "0" + (date.getMonth() + 1);
  // let d = "0" + date.getDate();
  return y + "-" + m.substring(m.length - 2, m.length);
}

export function formatDateTimeForHMSS(obj) {
  if (obj == null) {
    return null;
  }
  let date = new Date(obj);
  let y = 1900 + date.getYear();
  let m = "0" + (date.getMonth() + 1);
  let d = "0" + date.getDate();
  let h = "0" + date.getHours();
  let mm = "0" + date.getMinutes();
  let s = date.getSeconds();
  if (s.toString().length < 2) {
    s = "0" + s;
  }
  return (
    y +
    "-" +
    m.substring(m.length - 2, m.length) +
    "-" +
    d.substring(d.length - 2, d.length) +
    " " +
    h.substring(h.length - 2, h.length) +
    ":" +
    mm.substring(mm.length - 2, mm.length) +
    ":" +
    s
  );
}
